/*
 *******************************************************************************
 *
 * Copyright (C) 2019-2020 Dialog Semiconductor.
 * This computer program includes Confidential, Proprietary Information
 * of Dialog Semiconductor. All Rights Reserved.
 *
 *******************************************************************************
 */

package com.dialog.suotalib.suota;

import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;

import com.dialog.suotalib.global.SuotaProfile;

import java.lang.ref.WeakReference;

import androidx.annotation.NonNull;

class SendEndSignalOperation extends GattOperation{

    private final WeakReference<SuotaProtocol> suotaProtocolWeakReference;

    SendEndSignalOperation(@NonNull SuotaProtocol suotaProtocol, @NonNull BluetoothGattCharacteristic characteristic) {
        super(OperationType.WRITE, characteristic, SuotaProfile.Constants.SUOTA_END);
        suotaProtocolWeakReference = new WeakReference<>(suotaProtocol);
    }

    @Override
    boolean execute(@NonNull BluetoothGatt gatt) {
        if (suotaProtocolWeakReference.get() != null) {
            suotaProtocolWeakReference.get().notifyForSendingEndSignal();
        }
        return executeWriteCharacteristic(gatt);
    }
}
